﻿/* 
	Deletes all the other Tools in the current scene except for the Selected Tool
	This process cannot be undone. Process will also delete the undo history for the Selected Tool.
*/

/////////////////////////////////////////
// User Changeable Options ///////////////
/////////////////////////////////////////

/////////////////////////////////////////
/////////////////////////////////////////


[RoutineDef,CheckPolyMesh,

	[VarSet,editMode,[IGet,"Transform:Edit"]]
	[If,editMode,,
		[VarSet,DisplayNote,"Error: Tool is not in Edit mode. \n\nPlease select a PolyMesh3D object in Edit Mode and try again."]
  		/*1*/[NoteIButton,"OK",,,,,,,,,0xffffff,,,]
		[VarSet,result,[Note,DisplayNote,,,0x1f1f1f,,,,,,,,IMAGE_ZLogoForNotes.psd]]
		[Loop,1000,
			[If, result==1,
			// OK
			,]
		]
		[Exit]
    ]
        
    [If,[IExists,"Tool:Polygroups:Group Masked Clear Mask"],
        [If,[IsDisabled,"Tool:Polygroups:Group Masked Clear Mask"],
        	[VarSet,DisplayNote,"Error: The current Subtool is not a Polymesh3D object. \n\nPlease convert this Subtool to a PolyMesh3D object and try again."]
	  		/*1*/[NoteIButton,"OK",,,,,,,,,0xffffff,,,]
			[VarSet,result,[Note,DisplayNote,,,0x1f1f1f,,,,,,,,IMAGE_ZLogoForNotes.psd]]
			[Loop,1000,
				[If, result==1,
				// OK
				,]
			]
			[Exit]
        ,]
	,
		// 2.5D
		[VarSet,DisplayNote,"Error: The current Subtool is not a Polymesh3D object. \n\nPlease convert this Subtool to a PolyMesh3D object and try again."]
	  	/*1*/[NoteIButton,"OK",,,,,,,,,0xffffff,,,]
		[VarSet,result,[Note,DisplayNote,,,0x1f1f1f,,,,,,,,IMAGE_ZLogoForNotes.psd]]
		[Loop,1000,
			[If, result==1,
			// OK
			,]
		]
		[Exit]
	]

]// CheckPolyMesh



[RoutineDef,AskBeforeProceeding,

	[VarSet,DisplayNote,"This process will delete all Tools in the Tool palette except for the Selected Tool. \n(Selected Tool's undo history will be lost.) \n\n(This process cannot be undone.) \nDo you want to proceed?"]
	/*1*/[NoteIButton,"Cancel",,,,,,,,,0xffffff,,,]
	/*2*/[NoteIButton,"OK",,,,,,,,,0xffffff,,,]
	[VarSet,result,[Note,DisplayNote,,,0x1f1f1f,,,,,,,,IMAGE_ZLogoForNotes.psd]]
	[Loop,1000,
		[If,result==1,
			//CANCEL
			[Exit]
		,]
		[If,result==2,
			//OK
		,]
	]

]//Routine AskBeforeProceeding


[RoutineDef,StoreTool,

	// Copy the Selected Tool
	[IPress,"Tool:Copy Tool"]

	// Store Model Transform
	[MemDelete,Macro_TempMemBlock]
	[MemCreate,Macro_TempMemBlock,256]
	[MTransformGet,Macro_TempMemBlock]

]// StoreTool


[RoutineDef,ClearPolyMeshID,

	[ISet,"Tool:ItemInfo",41]
	[If,[IExists,"Tool:SubTool:Del All"],
		[VarSet,origID,[IGet,"Tool:ItemInfo"]]
		[IKeyPress,'2',[IPress,"Tool:SubTool:Del All"]]
		[VarSet,newID,[IGet,"Tool:ItemInfo"]]
		[If,origID==newID,
			// SubTool list has an error Duplicate to fix then delete
			[IPress,"Tool:SubTool:Duplicate"]
			[If,[IExists,"Tool:SubTool:Del All"],
				[IKeyPress,'2',[IPress,"Tool:SubTool:Del All"]]
			,]
		,]
	,]

]// ClearPolyMeshID


[RoutineDef,ScanTools,

	// Locate the Matcap Tool
	[VarSet,isMax,[IGetMax,"Tool:ItemInfo"]]
	[ISet,"Tool:ItemInfo",isMax]

	// Locate the MatCap Tool
	[Loop,512,
		[VarSet,Name,[IGetTitle,"Tool:Current Tool"]]

		[If,[StrFind,"MatCap",Name]>-1,
			[VarSet,isMatCap,[IGet,"Tool:ItemInfo"]]
			[LoopExit]
		,]

		[ISet,"Tool:ItemInfo",isMax-(n+1)]
	,n]

,isMatCap]// ScanTools


[RoutineDef,DeleteCurrentTool,

	[VarSet,delSelTool,1]
	[VarSet,Name,[IGetTitle,"Tool:Current Tool"]]

	// Check for MatCap Tool
	[If,[StrFind,"MatCap",Name]>-1,
		[VarSet,delSelTool,0]
	,]

	// Check for 3D Primitive Tools
	[If,[IExists,"Tool:Polygroups:Group Masked Clear Mask"],,
		[VarSet,delSelTool,0]
	]
	
	// Check for PolyMesh3D Star		
	[If,([StrFind,"PolyMesh3D",Name]>-1) && ([SubToolGetCount]<2),
		// Double Check
		[VarSet,PointCount,0]
		[Mesh3DGet,0,,,PointCount]
		[If,PointCount==14,
			[VarSet,delSelTool,0]
		,
			// SubTool list has an error Duplicate to fix
			[IPress,"Tool:SubTool:Duplicate"]
			[VarSet,delSelTool,1]
		]
	,]

,delSelTool]


[RoutineDef,ReturnTool,

	// Paste Original Selected Tool
	[IPress,"Tool:PolyMesh3D"]
	[IPress,"Tool:Paste Tool"]
	[IPress,"Layer:Clear"]

	// Return Model Transform
	[CanvasStroke,(ZObjStrokeV02n11=H3B6V14BH3B6V14CH3B6V14DH3B6V14EH3B6V150H3B6V151YH3B6V151K1XH3B6V152H3B6V152H3B6V153H3B6V153)]
	[MTransformSet,Macro_TempMemBlock]
	[MemDelete,Macro_TempMemBlock]
	[IPress,"Transform: Edit"]

	// Click the R button
	[IPress,29915]

]// ReturnTool


[RoutineDef,CleanToolPalette,

	[RoutineCall,StoreTool]
	[RoutineCall,ClearPolyMeshID]

	[VarSet,isMatCap,0]
	[RoutineCall,ScanTools,isMatCap]
	// Set Item Info after Scan
	[VarSet,isMax,[IGetMax,"Tool:ItemInfo"]]
	[ISet,"Tool:ItemInfo",isMax]

	[Loop,isMax-isMatCap,

		[If,[IGet,"Tool:ItemInfo"]==isMatCap,
			[LoopExit]
		,]

		[VarSet,DelTool,0]
		[RoutineCall,DeleteCurrentTool,DelTool]
		[If,DelTool,
			[If,[IExists,"Tool:SubTool:Del All"],
				[VarSet,origID,[IGet,"Tool:ItemInfo"]]
				[IKeyPress,'2',[IPress,"Tool:SubTool:Del All"]]
				[VarSet,newID,[IGet,"Tool:ItemInfo"]]
				[If,origID==newID,
					// SubTool list has an error Duplicate to fix then delete
					[IPress,"Tool:SubTool:Duplicate"]
					[If,[IExists,"Tool:SubTool:Del All"],
						[IKeyPress,'2',[IPress,"Tool:SubTool:Del All"]]
					,]
				]
			,]
		,]
		[ISet,"Tool:ItemInfo",isMax-(n+1)]

	,n]

	[RoutineCall,ReturnTool]

]// CleanToolPalette


[IButton,???,"Deletes all other Tools in the Tool palette except the Selected Tool.",
	[IShowActions,0]
	[IConfig,4.8]
	[RoutineCall,CheckPolyMesh]
	[RoutineCall,AskBeforeProceeding]
	[IFreeze,
		[RoutineCall,CleanToolPalette]
	]
,,1,,,]